package com.example.demo2.controller;

import com.example.demo2.Service.Accessimpl;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import net.sf.json.JSONObject;
@RestController
@RequestMapping("Access")
public class AccessOpenIdController {
    private static final String APPID = "";   //小程序的APPID
    private static final String APPSECRET = ""; //小程序的appsecret
    private static final String OPENID_URL = "https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret" +
            "=SECRET&js_code=JSCODE&grant_type=GRANTTYPE";//获取openid的地址
    private Accessimpl accessimple;
    @RequestMapping("OpenId")
    public String OpenID(String APPID,String APPSECRET,String Code,String granttype){
        String url = OPENID_URL.replace("APPID",APPID).replace("SECRET",APPSECRET).replace("JSCODE",Code).replace("GRANTTYPE",granttype);
        JSONObject jsonObject = accessimple.doGetStr(url);
        String OpenId = jsonObject.getString("openid");
        return OpenId;
    }

}
